import validateIdCard from './idcard'

export function checkIdcard(val){
  return validateIdCard(val)
}

export function checkPhone(val) {
  return /^1[3456789]\d{9}$/.test(val)
}

export function checkEmail(val) {
  return /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(val)
}

export function checkVerificationCode(val) {
  return /^\d{4}$/.test(val)
}

export function checkRequired(val){
  return !!val || val === 0
}

export function checkRules(val, rule){
  switch(rule){
    case 'idcard':
      return checkIdcard(val)
    case 'phone':
      return checkPhone(val)
    case 'email':
      return checkEmail(val)
    case 'code':
      return checkVerificationCode(val)
    case 'required':
      return checkRequired(val)
    default:
      return false
  }
}
